package com.slg.android.manyanime.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by E540 on 2015/3/11.
 */
public class AnimationCategory {
    /**
     * 分类id
     */
    private String id;
    /**
     * 分类名称
     */
    private String name;
    /**
     * 图片
     */
    private String pic;
    /**
     * 是否锁定
     */
    private boolean isLock;
    /**
     * 是否为分类
     */
    private boolean isGroup;


    public static List<AnimationCategory> parseCategory(JSONArray jsonArray) {
        ArrayList<AnimationCategory> list = new ArrayList<>();
        try {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                AnimationCategory group = new AnimationCategory();
                group.setName(jsonObject.getString("group"));
                group.setGroup(true);
                list.add(group);
                JSONArray categories = jsonObject.getJSONArray("list");
                for (int j = 0; j < categories.length(); j++) {
                    JSONObject category = categories.getJSONObject(j);
                    AnimationCategory c = new AnimationCategory();
                    c.setGroup(false);
                    c.setId(category.getString("id"));
                    c.setName(category.getString("name"));
                    c.setPic(category.getString("pic"));
                    c.setLock(category.getBoolean("is_lock"));
                    list.add(c);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return list;
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPic() {
        return pic;
    }

    public void setPic(String pic) {
        this.pic = pic;
    }

    public boolean isLock() {
        return isLock;
    }

    public void setLock(boolean isLock) {
        this.isLock = isLock;
    }

    public boolean isGroup() {
        return isGroup;
    }

    public void setGroup(boolean isGroup) {
        this.isGroup = isGroup;
    }
}
